import 'package:demo/config/build_config.dart';
import 'package:demo/constants/network_path.dart';
import 'package:demo/core/network/http.dart';
import 'package:demo/model/entity/home_entity.dart';
import 'package:demo/model/entity/home_recommend_entity.dart';

/// 首页网络请求封装
class HomeRepository {
  /// 私有化，不允许New
  HomeRepository._();

  /// 基础栏目布局
  static Future<HomeEntity?> get getColumnLayout async {
    return HomeEntity.fromJson({
      "category": [
        {
          "id": 1,
          "name": "新鲜蔬菜",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/52998/16/2133/4919/5cfe3079E7f31a23e/0ef02388cb3205e3.jpg"
        },
        {
          "id": 2,
          "name": "时令水果",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/49107/14/3176/6019/5d0eea59E238562fd/2576bcda7fc37edd.jpg!q70.dpg"
        },
        {
          "id": 3,
          "name": "肉禽蛋",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/55710/36/5173/8351/5d2da86bE2ac4dee5/10957ef8d1ceec5f.jpg!q70.dpg"
        },
        {
          "id": 4,
          "name": "水产海鲜",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/99252/13/11946/18637/5e412631Ecf6310f7/320ad6fce983b9c3.jpg!q70.dpg"
        },
        {
          "id": 5,
          "name": "乳品雪糕",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/64254/35/1600/5474/5cfe311bE6b658420/c376ef47a5c89d23.jpg!q70.dpg"
        },
        {
          "id": 6,
          "name": "米面粮油",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/52998/16/2133/4919/5cfe3079E7f31a23e/0ef02388cb3205e3.jpg",
        },
        {
          "id": 7,
          "name": "酒饮零食",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/52998/16/2133/4919/5cfe3079E7f31a23e/0ef02388cb3205e3.jpg",
        },
        {
          "id": 8,
          "name": "方便速食",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/48937/35/2912/7045/5d0b6e2aE0e804104/9bc8a882b83c2108.jpg!q70.dpg",
        },
        {
          "id": 9,
          "name": "邀请有礼",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/66255/7/1579/4738/5cfe300dE50487936/ec2699b670750e51.jpg!q70.dpg",
        },
        {
          "id": 10,
          "name": "绿卡专享",
          "imgUrl":
              "https://m.360buyimg.com/babel/s116x116_jfs/t1/83450/37/2380/4616/5d0b296fE083e2387/f301574fbc05650d.jpg!q70.dpg",
        }
      ],
      "banner": [
        {
          "id": 1,
          "imgUrl":
              "https://m.360buyimg.com/mobilecms/s700x280_jfs/t1/192458/33/5940/113121/60b5d26dE08d46970/bb0ec0a649f62303.jpg!cr_1053x420_4_0!q70.jpg",
          "name": "轮播1"
        },
        {
          "id": 2,
          "imgUrl":
              "https://m.360buyimg.com/mobilecms/s700x280_jfs/t1/178418/25/6633/147613/60b45d0bE817a7162/525b9b850f1b99a2.jpg!cr_1053x420_4_0!q70.jpg",
          "name": "轮播2"
        },
        {
          "id": 3,
          "imgUrl":
              "https://m.360buyimg.com/mobilecms/s700x280_jfs/t1/172985/20/11254/250873/60ab712bE2cfd0e52/f184257039a404d1.png!cr_1053x420_4_0!q70.jpg",
          "name": "轮播3"
        },
        {
          "id": 4,
          "imgUrl":
              "https://m.360buyimg.com/mobilecms/s700x280_jfs/t1/167245/17/13432/149823/60540ceeE0a928512/677088217d8a00aa.jpg!cr_1053x420_4_0!q70.jpg",
          "name": "轮播4"
        },
      ]
    });
  }

  /// 首页推荐数据
  static Future<List<LinkData>?> getRecommendLayout(int pageSize, int pageNum) async {
    var res = await HttpClientDio.instance.get(
      "${BuildConfig.shared.getBaiduPictureHostUrl}$baiduPictureApi",
      queryParameters: <String, dynamic>{
        "pn": pageNum * pageSize,
        "rn": 30,
        "tn": "albumsdetail",
        "word": "航拍地球系列",
        "album_tab": "设计素材",
        "album_id": 312,
        "ic": 0,
        "curPageNum": pageNum
      },
    );
    if (res.data != null) {
      final HomeRecommendEntity entity = HomeRecommendEntity.fromJson(res.data);
      return entity.albumdata!.linkData ?? [];
    }
    return null;
  }
}
